<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>webdoc</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            webdoc
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li class="active"><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-dva.html">30.cms-10-dva</a></li><li><a href="../html/30.cms-11-front.html">30.cms-11-front</a></li><li><a href="../html/31.cms-12-api.html">31.cms-12-api</a></li><li><a href="../html/31.cms-13-front.html">31.cms-13-front</a></li><li><a href="../html/31.cms-14-deploy.html">31.cms-14-deploy</a></li><li><a href="../html/32.ant.html">32.ant</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. 什么是MongoDB">1. 什么是MongoDB</a></li><li><a href="#t12. MongoDB安装">2. MongoDB安装</a><ul><li><a href="#t22.1 windows安装">2.1 windows安装</a></li><li><a href="#t32.2 mac安装">2.2 mac安装</a></li></ul></li><li><a href="#t43. mongodb启动与连接">3. mongodb启动与连接</a><ul><li><a href="#t53.1 windows启动服务器端">3.1 windows启动服务器端</a></li><li><a href="#t63.2 启动客户端连接服务器">3.2 启动客户端连接服务器</a></li></ul></li><li><a href="#t74. 配置Mongodb服务">4. 配置Mongodb服务</a><ul><li><a href="#t84.1 删除服务">4.1 删除服务</a></li><li><a href="#t94.2 添加服务">4.2 添加服务</a></li></ul></li><li><a href="#t105. MongoDB基本概念">5. MongoDB基本概念</a></li><li><a href="#t116. 数据库操作">6. 数据库操作</a><ul><li><a href="#t126.1 使用数据库">6.1 使用数据库</a></li><li><a href="#t136.2 查看所有数据库">6.2 查看所有数据库</a></li><li><a href="#t146.3 查看当前使用的数据库">6.3 查看当前使用的数据库</a></li><li><a href="#t156.4 删除数据库">6.4 删除数据库</a></li></ul></li><li><a href="#t167. 集合操作">7. 集合操作</a><ul><li><a href="#t177.1 查看集合帮助">7.1 查看集合帮助</a></li><li><a href="#t187.2 查看数据库下的集合">7.2 查看数据库下的集合</a></li><li><a href="#t197.3 创建集合">7.3 创建集合</a></li></ul></li><li><a href="#t208. 插入文档">8. 插入文档</a><ul><li><a href="#t218.1 insert">8.1 insert</a></li><li><a href="#t228.2 save">8.2 save</a></li></ul></li><li><a href="#t239. 更新文档">9. 更新文档</a><ul><li><a href="#t249.1 $set">9.1 $set</a></li><li><a href="#t259.2 $inc">9.2 $inc</a></li><li><a href="#t269.3 $unset">9.3 $unset</a></li><li><a href="#t279.4 upsert">9.4 upsert</a></li><li><a href="#t289.5 multi">9.5 multi</a></li><li><a href="#t299.6 $push">9.6 $push</a></li><li><a href="#t309.7 $ne">9.7 $ne</a></li><li><a href="#t319.8 $addToSet">9.8 $addToSet</a></li><li><a href="#t329.9 $each">9.9 $each</a></li><li><a href="#t339.10  $pop">9.10  $pop</a></li><li><a href="#t349.11 修改指定索引元素">9.11 修改指定索引元素</a></li><li><a href="#t359.12  runCommand">9.12  runCommand</a></li></ul></li><li><a href="#t3610. 文档的删除">10. 文档的删除</a></li><li><a href="#t3711. 查询文档">11. 查询文档</a><ul><li><a href="#t3811.1 find">11.1 find</a></li><li><a href="#t3911.2 查询指定列">11.2 查询指定列</a></li><li><a href="#t4011.3 findOne">11.3 findOne</a></li><li><a href="#t4111.4 $in">11.4 $in</a></li><li><a href="#t4211.5 $nin">11.5 $nin</a></li><li><a href="#t4311.6 $nin">11.6 $nin</a></li><li><a href="#t4411.7  $not">11.7  $not</a></li><li><a href="#t4511.8  array">11.8  array</a></li><li><a href="#t4611.9   where">11.9   where</a></li><li><a href="#t4711.10   cursor">11.10   cursor</a></li></ul></li><li><a href="#t4812. 条件操作符">12. 条件操作符</a><ul><li><a href="#t4912.1 大于操作符">12.1 大于操作符</a></li><li><a href="#t5012.2 大于等于操作符">12.2 大于等于操作符</a></li><li><a href="#t5112.3 小于操作符">12.3 小于操作符</a></li><li><a href="#t5212.4 小于等于操作符">12.4 小于等于操作符</a></li><li><a href="#t5312.5 同时使用 $gte和$lte">12.5 同时使用 $gte和$lte</a></li><li><a href="#t5412.6 等于">12.6 等于</a></li><li><a href="#t5512.7 使用 _id进行查询">12.7 使用 _id进行查询</a></li><li><a href="#t5612.8 查询结果集的条数">12.8 查询结果集的条数</a></li><li><a href="#t5712.9 正则匹配">12.9 正则匹配</a></li></ul></li><li><a href="#t5813. 与和或">13. 与和或</a><ul><li><a href="#t5913.1 and">13.1 and</a></li><li><a href="#t6013.2 or">13.2 or</a></li><li><a href="#t6113.3 and和or联用">13.3 and和or联用</a></li></ul></li><li><a href="#t6214. 分页查询">14. 分页查询</a><ul><li><a href="#t6314.1 limit">14.1 limit</a></li><li><a href="#t6414.2 skip">14.2 skip</a></li><li><a href="#t6514.3 skip+limit">14.3 skip+limit</a></li><li><a href="#t6614.4 sort排序">14.4 sort排序</a></li><li><a href="#t6715. 执行脚本">15. 执行脚本</a></li><li><a href="#t6816 索引">16 索引</a></li><li><a href="#t69备份与导出">备份与导出</a></li><li><a href="#t70权限">权限</a></li></ul></li><li><a href="#t71附录">附录</a><ul><li><a href="#t72ObjectId构成">ObjectId构成</a></li></ul></li><li><a href="#t73附录">附录</a><ul><li><a href="#t74Mongodb启动命令mongod参数说明">Mongodb启动命令mongod参数说明</a></li></ul></li><li><a href="#t75集合命令">集合命令</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. &#x4EC0;&#x4E48;&#x662F;MongoDB">1. &#x4EC0;&#x4E48;&#x662F;MongoDB <a href="#t01. &#x4EC0;&#x4E48;&#x662F;MongoDB"> # </a></h2>
<ul>
<li>MongoDB&#x662F;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E;&#x5206;&#x5E03;&#x5F0F;&#x6587;&#x4EF6;&#x5B58;&#x50A8;&#x7684;&#x5F00;&#x6E90;&#x6570;&#x636E;&#x5E93;&#x7CFB;&#x7EDF;</li>
<li>MongoDB &#x5C06;&#x6570;&#x636E;&#x5B58;&#x50A8;&#x4E3A;&#x4E00;&#x4E2A;&#x6587;&#x6863;&#xFF0C;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x7531;&#x952E;&#x503C;(key=&gt;value)&#x5BF9;&#x7EC4;&#x6210;&#x3002;MongoDB &#x6587;&#x6863;&#x7C7B;&#x4F3C;&#x4E8E; JSON &#x5BF9;&#x8C61;&#x3002;&#x5B57;&#x6BB5;&#x503C;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x5176;&#x4ED6;&#x6587;&#x6863;&#xFF0C;&#x6570;&#x7EC4;&#x53CA;&#x6587;&#x6863;&#x6570;&#x7EC4;&#x3002;</li>
</ul>
<h2 id="t12. MongoDB&#x5B89;&#x88C5;">2. MongoDB&#x5B89;&#x88C5; <a href="#t12. MongoDB&#x5B89;&#x88C5;"> # </a></h2>
<h3 id="t22.1 windows&#x5B89;&#x88C5;">2.1 windows&#x5B89;&#x88C5; <a href="#t22.1 windows&#x5B89;&#x88C5;"> # </a></h3>
<p><a href="https://www.mongodb.org/downloads">Windows&#x5B98;&#x65B9;&#x5B89;&#x88C5;&#x6307;&#x5357;</a></p>
<ul>
<li><p>mongodb32&#x4F4D;&#x5B89;&#x88C5;&#x7248;
&#x94FE;&#x63A5;: <a href="https://pan.baidu.com/s/1SHJ1vre_CQOE3u-W0zniqQ">https://pan.baidu.com/s/1SHJ1vre_CQOE3u-W0zniqQ</a> &#x5BC6;&#x7801;: chan</p>
</li>
<li><p>MongoDB64&#x4F4D;&#x7EFF;&#x8272;&#x7248;
&#x94FE;&#x63A5;: <a href="https://pan.baidu.com/s/1EkAB2SrcU1mfMfff_WDxtA">https://pan.baidu.com/s/1EkAB2SrcU1mfMfff_WDxtA</a> &#x5BC6;&#x7801;: w913</p>
</li>
<li><p>mongo&#x5BA2;&#x6237;&#x7AEF;
&#x94FE;&#x63A5;: <a href="https://pan.baidu.com/s/1YFxLZ-55D-WFR8os2fXN0A">https://pan.baidu.com/s/1YFxLZ-55D-WFR8os2fXN0A</a> &#x5BC6;&#x7801;: 61qd</p>
</li>
</ul>
<h3 id="t32.2 mac&#x5B89;&#x88C5;">2.2 mac&#x5B89;&#x88C5; <a href="#t32.2 mac&#x5B89;&#x88C5;"> # </a></h3>
<p><a href="https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/">Mac&#x5B98;&#x65B9;&#x5B89;&#x88C5;&#x6307;&#x5357;</a></p>
<ol>
<li><p>&#x5148;&#x5B89;&#x88C5;homebrew</p>
<pre><code>http://brew.sh/
</code></pre></li>
<li><p>&#x4F7F;&#x7528;brew&#x5B89;&#x88C5;mongodb</p>
<pre><code>brew install mongodb
</code></pre></li>
<li><p>&#x518D;&#x5B89;&#x88C5;&#x53EF;&#x89C6;&#x5316;&#x5DE5;&#x5177;
<a href="https://robomongo.org/">Robomongo</a></p>
</li>
</ol>
<h2 id="t43. mongodb&#x542F;&#x52A8;&#x4E0E;&#x8FDE;&#x63A5;">3. mongodb&#x542F;&#x52A8;&#x4E0E;&#x8FDE;&#x63A5; <a href="#t43. mongodb&#x542F;&#x52A8;&#x4E0E;&#x8FDE;&#x63A5;"> # </a></h2>
<h3 id="t53.1 windows&#x542F;&#x52A8;&#x670D;&#x52A1;&#x5668;&#x7AEF;">3.1 windows&#x542F;&#x52A8;&#x670D;&#x52A1;&#x5668;&#x7AEF; <a href="#t53.1 windows&#x542F;&#x52A8;&#x670D;&#x52A1;&#x5668;&#x7AEF;"> # </a></h3>
<ol>
<li>&#x627E;&#x5230;mongodb&#x5B89;&#x88C5;&#x76EE;&#x5F55;,&#x4E00;&#x822C;&#x662F; <code>C:\Program Files\MongoDB 2.6 Standard\bin</code></li>
<li>&#x6309;&#x4E0B;Shift+&#x9F20;&#x6807;&#x53F3;&#x952E;,&#x9009;&#x62E9;&#x5728;&#x6B64;&#x5904;&#x6253;&#x5F00;&#x547D;&#x4EE4;&#x7A97;&#x53E3;
<img src="http://7xjf2l.com2.z0.glb.qiniucdn.com/3.mongodb-1.png" class="img-responsive"></li>
<li>&#x5728;&#x9664;C&#x76D8;&#x5916;&#x7684;&#x76D8;&#x7B26;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x76EE;&#x5F55;,&#x5982; <code>D:\Mongodb\data</code></li>
<li>&#x5728;&#x547D;&#x4EE4;&#x884C;&#x4E2D;&#x8F93;&#x5165;<code>mongod --dbpath=&#x521A;&#x521B;&#x5EFA;&#x7684;&#x7A7A;&#x76EE;&#x5F55;</code>,&#x5982;<pre><code>mongod --dbpath=D:\Mongodb\data
</code></pre></li>
<li><p>&#x518D;&#x6309;&#x56DE;&#x8F66;&#x952E;
<img src="http://7xjf2l.com2.z0.glb.qiniucdn.com/3.mongodb-2.png" class="img-responsive"></p>
</li>
<li><p>&#x5982;&#x679C;&#x51FA;&#x73B0;<code>waiting for connections on port 27017</code>&#x5C31;&#x8868;&#x793A;<strong>&#x542F;&#x52A8;&#x6210;&#x529F;</strong>,&#x5DF2;&#x7ECF;&#x5728;27017&#x7AEF;&#x53E3;&#x4E0A;&#x76D1;&#x542C;&#x4E86;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x8BF7;&#x6C42;</p>
</li>
<li><p>&#x6CE8;&#x610F;&#xFF1A;<code>--dbpath</code>&#x540E;&#x7684;&#x503C;&#x8868;&#x793A;&#x6570;&#x636E;&#x5E93;&#x6587;&#x4EF6;&#x7684;&#x5B58;&#x50A8;&#x8DEF;&#x5F84;,&#x800C;&#x4E14;&#x540E;&#x9762;&#x7684;&#x8DEF;&#x5F84;&#x5FC5;&#x987B;&#x4E8B;&#x5148;&#x521B;&#x5EFA;&#x597D;&#xFF0C;&#x5FC5;&#x987B;&#x5DF2;&#x7ECF;<strong>&#x5B58;&#x5728;</strong>&#xFF0C;&#x5426;&#x5219;&#x670D;&#x52A1;&#x5F00;&#x542F;&#x5931;&#x8D25;</p>
</li>
<li><p>&#x6CE8;&#x610F;&#xFF1A;&#x8FD9;&#x4E2A;&#x547D;&#x4EE4;&#x7A97;&#x4F53;&#x7EDD;&#x5BF9;<strong>&#x4E0D;&#x80FD;&#x5173;</strong>,&#x5173;&#x95ED;&#x8FD9;&#x4E2A;&#x7A97;&#x53E3;&#x5C31;&#x76F8;&#x5F53;&#x4E8E;&#x505C;&#x6B62;&#x4E86;<code>mongodb</code>&#x670D;&#x52A1;</p>
</li>
</ol>
<h3 id="t63.2 &#x542F;&#x52A8;&#x5BA2;&#x6237;&#x7AEF;&#x8FDE;&#x63A5;&#x670D;&#x52A1;&#x5668;">3.2 &#x542F;&#x52A8;&#x5BA2;&#x6237;&#x7AEF;&#x8FDE;&#x63A5;&#x670D;&#x52A1;&#x5668; <a href="#t63.2 &#x542F;&#x52A8;&#x5BA2;&#x6237;&#x7AEF;&#x8FDE;&#x63A5;&#x670D;&#x52A1;&#x5668;"> # </a></h3>
<ol>
<li>&#x627E;&#x5230;mongodb&#x5B89;&#x88C5;&#x76EE;&#x5F55;,&#x4E00;&#x822C;&#x662F; <code>C:\Program Files\MongoDB 2.6 Standard\bin</code></li>
<li><p>&#x6309;&#x4E0B;Shift+&#x9F20;&#x6807;&#x53F3;&#x952E;,&#x9009;&#x62E9;&#x5728;&#x6B64;&#x5904;&#x6253;&#x5F00;&#x547D;&#x4EE4;&#x7A97;&#x53E3;
<img src="http://7xjf2l.com2.z0.glb.qiniucdn.com/3.mongodb-1.png" class="img-responsive"></p>
</li>
<li><p>&#x547D;&#x4EE4;&#x7A97;&#x4F53;&#x4E2D;&#x8F93;&#x5165; mongo --host=127.0.0.1 &#x6216;&#x8005; mongo &#x6309;&#x56DE;&#x8F66;&#x952E;</p>
<blockquote>
<p>&#x5907;&#x6CE8;&#xFF1A;--host&#x540E;&#x7684;&#x503C;&#x8868;&#x793A;&#x670D;&#x52A1;&#x5668;&#x7684;ip&#x5730;&#x5740;
&#x5907;&#x6CE8;&#xFF1A; --host=127.0.0.1 &#x8868;&#x793A;&#x7684;&#x5C31;&#x662F;&#x672C;&#x5730;&#x670D;&#x52A1;&#x5668;,&#x6BCF;&#x6B21;&#x6570;&#x636E;&#x5E93;&#x90FD;&#x4F1A;&#x9ED8;&#x8BA4;&#x8FDE;&#x63A5;test&#x6570;&#x636E;&#x5E93;</p>
</blockquote>
</li>
</ol>
<hr>
<p><img src="http://7xjf2l.com2.z0.glb.qiniucdn.com/3.mongodb-4.png" class="img-responsive"></p>
<h2 id="t74. &#x914D;&#x7F6E;Mongodb&#x670D;&#x52A1;">4. &#x914D;&#x7F6E;Mongodb&#x670D;&#x52A1; <a href="#t74. &#x914D;&#x7F6E;Mongodb&#x670D;&#x52A1;"> # </a></h2>
<h3 id="t84.1 &#x5220;&#x9664;&#x670D;&#x52A1;">4.1 &#x5220;&#x9664;&#x670D;&#x52A1; <a href="#t84.1 &#x5220;&#x9664;&#x670D;&#x52A1;"> # </a></h3>
<pre><code class="lang-js">sc <span class="hljs-keyword">delete</span> mongodb
</code></pre>
<h3 id="t94.2 &#x6DFB;&#x52A0;&#x670D;&#x52A1;">4.2 &#x6DFB;&#x52A0;&#x670D;&#x52A1; <a href="#t94.2 &#x6DFB;&#x52A0;&#x670D;&#x52A1;"> # </a></h3>
<pre><code class="lang-js">mongod.exe --dbpath E:\mdata --logpath E:\mlog --logappend --directoryperdb --serviceName mongodb --install

net start mongodb
net stop mongodb
</code></pre>
<h2 id="t105. MongoDB&#x57FA;&#x672C;&#x6982;&#x5FF5;">5. MongoDB&#x57FA;&#x672C;&#x6982;&#x5FF5; <a href="#t105. MongoDB&#x57FA;&#x672C;&#x6982;&#x5FF5;"> # </a></h2>
<ul>
<li><strong>&#x6570;&#x636E;&#x5E93;</strong> MongoDB&#x7684;&#x5355;&#x4E2A;&#x5B9E;&#x4F8B;&#x53EF;&#x4EE5;&#x5BB9;&#x7EB3;<strong>&#x591A;&#x4E2A;</strong>&#x72EC;&#x7ACB;&#x7684;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x6BD4;&#x5982;&#x4E00;&#x4E2A;&#x5B66;&#x751F;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#x5C31;&#x53EF;&#x4EE5;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x5B9E;&#x4F8B;</li>
<li><strong>&#x96C6;&#x5408;</strong> &#x6570;&#x636E;&#x5E93;&#x662F;&#x7531;&#x96C6;&#x5408;&#x7EC4;&#x6210;&#x7684;,&#x4E00;&#x4E2A;&#x96C6;&#x5408;&#x7528;&#x6765;&#x8868;&#x793A;&#x4E00;&#x4E2A;<strong>&#x5B9E;&#x4F53;</strong>,&#x5982;&#x5B66;&#x751F;&#x96C6;&#x5408;</li>
<li><strong>&#x6587;&#x6863;</strong> &#x96C6;&#x5408;&#x662F;&#x7531;&#x6587;&#x6863;&#x7EC4;&#x6210;&#x7684;&#xFF0C;&#x4E00;&#x4E2A;&#x6587;&#x6863;&#x8868;&#x793A;&#x4E00;&#x6761;<strong>&#x8BB0;&#x5F55;</strong>,&#x6BD4;&#x5982;&#x4E00;&#x4F4D;&#x540C;&#x5B66;&#x5F20;&#x4E09;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x6587;&#x6863;</li>
</ul>
<p><img src="http://7xjf2l.com1.z0.glb.clouddn.com/mongodbstructure.jpg" class="img-responsive">
<img src="http://7xjf2l.com1.z0.glb.clouddn.com/mongovue.png" class="img-responsive"></p>
<h2 id="t116. &#x6570;&#x636E;&#x5E93;&#x64CD;&#x4F5C;">6. &#x6570;&#x636E;&#x5E93;&#x64CD;&#x4F5C; <a href="#t116. &#x6570;&#x636E;&#x5E93;&#x64CD;&#x4F5C;"> # </a></h2>
<h3 id="t126.1 &#x4F7F;&#x7528;&#x6570;&#x636E;&#x5E93;">6.1 &#x4F7F;&#x7528;&#x6570;&#x636E;&#x5E93; <a href="#t126.1 &#x4F7F;&#x7528;&#x6570;&#x636E;&#x5E93;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>use database_name      database_name&#x4EE3;&#x8868;&#x6570;&#x636E;&#x5E93;&#x7684;&#x540D;&#x5B57;
</code></pre><p>&#x6CE8;&#xFF1A;&#x5982;&#x679C;&#x6B64;&#x6570;&#x636E;&#x5E93;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x5207;&#x6362;&#x5230;&#x6B64;&#x6570;&#x636E;&#x5E93;&#x4E0B;,&#x5982;&#x679C;&#x6B64;&#x6570;&#x636E;&#x5E93;&#x8FD8;&#x4E0D;&#x5B58;&#x5728;&#x4E5F;&#x53EF;&#x4EE5;&#x5207;&#x8FC7;&#x6765;</p>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x5207;&#x6362;&#x5230; <code>school</code>&#x6570;&#x636E;&#x5E93;&#x4E0B;</p>
<h3 id="t136.2 &#x67E5;&#x770B;&#x6240;&#x6709;&#x6570;&#x636E;&#x5E93;">6.2 &#x67E5;&#x770B;&#x6240;&#x6709;&#x6570;&#x636E;&#x5E93; <a href="#t136.2 &#x67E5;&#x770B;&#x6240;&#x6709;&#x6570;&#x636E;&#x5E93;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>show dbs
</code></pre><blockquote>
<p>&#x5907;&#x6CE8;: &#x6211;&#x4EEC;&#x521A;&#x521B;&#x5EFA;&#x7684;&#x6570;&#x636E;&#x5E93;<code>school</code>&#x5982;&#x679C;&#x4E0D;&#x5728;&#x5217;&#x8868;&#x5185;&#xFF0C; &#x8981;&#x663E;&#x793A;&#x5B83;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5411;<code>school</code>&#x6570;&#x636E;&#x5E93;&#x63D2;&#x5165;&#x4E00;&#x4E9B;&#x6570;&#x636E;</p>
</blockquote>
<pre><code class="lang-js">db.students.insert({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">1</span>});
</code></pre>
<h3 id="t146.3 &#x67E5;&#x770B;&#x5F53;&#x524D;&#x4F7F;&#x7528;&#x7684;&#x6570;&#x636E;&#x5E93;">6.3 &#x67E5;&#x770B;&#x5F53;&#x524D;&#x4F7F;&#x7528;&#x7684;&#x6570;&#x636E;&#x5E93; <a href="#t146.3 &#x67E5;&#x770B;&#x5F53;&#x524D;&#x4F7F;&#x7528;&#x7684;&#x6570;&#x636E;&#x5E93;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db &#x6216; db.getName()
</code></pre><blockquote>
<p>&#x6CE8;&#xFF1A;db&#x4EE3;&#x8868;&#x7684;&#x662F;&#x5F53;&#x524D;&#x6570;&#x636E;&#x5E93; &#x4E5F;&#x5C31;&#x662F;school&#x8FD9;&#x4E2A;&#x6570;&#x636E;&#x5E93;</p>
<h3 id="t156.4 &#x5220;&#x9664;&#x6570;&#x636E;&#x5E93;">6.4 &#x5220;&#x9664;&#x6570;&#x636E;&#x5E93; <a href="#t156.4 &#x5220;&#x9664;&#x6570;&#x636E;&#x5E93;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.dropDatabase()
</code></pre></blockquote>
<h2 id="t167. &#x96C6;&#x5408;&#x64CD;&#x4F5C;">7. &#x96C6;&#x5408;&#x64CD;&#x4F5C; <a href="#t167. &#x96C6;&#x5408;&#x64CD;&#x4F5C;"> # </a></h2>
<h3 id="t177.1 &#x67E5;&#x770B;&#x96C6;&#x5408;&#x5E2E;&#x52A9;">7.1 &#x67E5;&#x770B;&#x96C6;&#x5408;&#x5E2E;&#x52A9; <a href="#t177.1 &#x67E5;&#x770B;&#x96C6;&#x5408;&#x5E2E;&#x52A9;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.students.help()
</code></pre><h3 id="t187.2 &#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x96C6;&#x5408;">7.2 &#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x96C6;&#x5408; <a href="#t187.2 &#x67E5;&#x770B;&#x6570;&#x636E;&#x5E93;&#x4E0B;&#x7684;&#x96C6;&#x5408;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>show collections
</code></pre><p><strong>&#x5B9E;&#x4F8B;</strong>
<img src="http://7xjf2l.com2.z0.glb.qiniucdn.com/3.mongodb-11.png" class="img-responsive"></p>
<h3 id="t197.3 &#x521B;&#x5EFA;&#x96C6;&#x5408;">7.3 &#x521B;&#x5EFA;&#x96C6;&#x5408; <a href="#t197.3 &#x521B;&#x5EFA;&#x96C6;&#x5408;"> # </a></h3>
<p><strong>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7A7A;&#x96C6;&#x5408;</strong></p>
<pre><code>db.createCollection(collection_Name)
</code></pre><ul>
<li>collection_Name&#x96C6;&#x5408;&#x7684;&#x540D;&#x79F0;</li>
</ul>
<p><strong>&#x521B;&#x5EFA;&#x96C6;&#x5408;&#x5E76;&#x63D2;&#x5165;&#x4E00;&#x4E2A;&#x6587;&#x6863;</strong></p>
<ul>
<li>collection_Name&#x96C6;&#x5408;&#x7684;&#x540D;&#x79F0;</li>
<li>document&#x8981;&#x63D2;&#x5165;&#x7684;&#x6587;&#x6863;</li>
</ul>
<pre><code>db.collection_Name.insert(document)
</code></pre><h2 id="t208. &#x63D2;&#x5165;&#x6587;&#x6863;">8. &#x63D2;&#x5165;&#x6587;&#x6863; <a href="#t208. &#x63D2;&#x5165;&#x6587;&#x6863;"> # </a></h2>
<h3 id="t218.1 insert">8.1 insert <a href="#t218.1 insert"> # </a></h3>
<p> <strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code class="lang-js"> db.collection_name.insert(<span class="hljs-built_in">document</span>)
<span class="hljs-string">`
</span></code></pre>
<p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collection_name &#x96C6;&#x5408;&#x7684;&#x540D;&#x5B57;</li>
<li>document &#x63D2;&#x5165;&#x7684;&#x6587;&#x6863;</li>
</ul>
<blockquote>
<p>&#x6BCF;&#x5F53;&#x63D2;&#x5165;&#x4E00;&#x6761;&#x65B0;&#x6587;&#x6863;&#x7684;&#x65F6;&#x5019;mongodb&#x4F1A;&#x81EA;&#x52A8;&#x4E3A;&#x6B64;&#x6587;&#x6863;&#x751F;&#x6210;&#x4E00;&#x4E2A;<code>_id</code>&#x5C5E;&#x6027;,_id&#x4E00;&#x5B9A;&#x662F;&#x552F;&#x4E00;&#x7684;&#xFF0C;&#x7528;&#x6765;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x4E00;&#x4E2A;&#x6587;&#x6863;
 _id&#x4E5F;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x6307;&#x5B9A;&#xFF0C;&#x4F46;&#x5982;&#x679C;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x6B64;&#x96C6;&#x5408;&#x4E0B;&#x5DF2;&#x7ECF;&#x6709;&#x6B64;_id&#x7684;&#x8BDD;&#x63D2;&#x5165;&#x4F1A;&#x5931;&#x8D25;</p>
</blockquote>
<pre><code class="lang-js">&gt; db.students.insert({<span class="hljs-attr">_id</span>:<span class="hljs-number">1</span>,<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">1</span>});
WriteResult({ <span class="hljs-string">&quot;nInserted&quot;</span> : <span class="hljs-number">1</span> })
&gt; db.students.insert({<span class="hljs-attr">_id</span>:<span class="hljs-number">1</span>,<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">1</span>});
</code></pre>
<h3 id="t228.2 save">8.2 save <a href="#t228.2 save"> # </a></h3>
<p> <strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code class="lang-js">db.collection_name.save(<span class="hljs-built_in">document</span>)
</code></pre>
<p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collection_name &#x96C6;&#x5408;&#x7684;&#x540D;&#x5B57;</li>
<li>document &#x63D2;&#x5165;&#x7684;&#x6587;&#x6863;</li>
</ul>
<blockquote>
<p>&#x6CE8;&#xFF1A;&#x5982;&#x679C;&#x4E0D;&#x6307;&#x5B9A; _id &#x5B57;&#x6BB5; save() &#x65B9;&#x6CD5;&#x7C7B;&#x4F3C;&#x4E8E; insert() &#x65B9;&#x6CD5;&#x3002;&#x5982;&#x679C;&#x6307;&#x5B9A; _id &#x5B57;&#x6BB5;&#xFF0C;&#x5219;&#x4F1A;&#x66F4;&#x65B0;&#x8BE5; _id &#x7684;&#x6570;&#x636E;&#x3002;</p>
</blockquote>
<p><strong>&#x5B9E;&#x4F8B;</strong></p>
<pre><code class="lang-js">&gt; db.students.save({<span class="hljs-attr">_id</span>:<span class="hljs-number">1</span>,<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">1</span>});
WriteResult({ <span class="hljs-string">&quot;nMatched&quot;</span> : <span class="hljs-number">1</span>, <span class="hljs-string">&quot;nUpserted&quot;</span> : <span class="hljs-number">0</span>, <span class="hljs-string">&quot;nModified&quot;</span> : <span class="hljs-number">0</span> })
&gt; db.students.save({<span class="hljs-attr">_id</span>:<span class="hljs-number">1</span>,<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zfpx&apos;</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">100</span>});
WriteResult({ <span class="hljs-string">&quot;nMatched&quot;</span> : <span class="hljs-number">1</span>, <span class="hljs-string">&quot;nUpserted&quot;</span> : <span class="hljs-number">0</span>, <span class="hljs-string">&quot;nModified&quot;</span> : <span class="hljs-number">1</span> })
</code></pre>
<h2 id="t239. &#x66F4;&#x65B0;&#x6587;&#x6863;">9. &#x66F4;&#x65B0;&#x6587;&#x6863; <a href="#t239. &#x66F4;&#x65B0;&#x6587;&#x6863;"> # </a></h2>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code class="lang-js">db.collection.update(
   &lt;query&gt;,
   &lt;updateObj&gt;,
   {
     upsert: &lt;boolean&gt;,
     multi: &lt;boolean&gt;
   }
)
</code></pre>
<p><strong>&#x53C2;&#x6570;&#x8BF4;&#x660E;</strong></p>
<ul>
<li>query  &#x67E5;&#x8BE2;&#x6761;&#x4EF6;,&#x6307;&#x5B9A;&#x8981;&#x66F4;&#x65B0;&#x7B26;&#x5408;&#x54EA;&#x4E9B;&#x6761;&#x4EF6;&#x7684;&#x6587;&#x6863;</li>
<li>update  &#x66F4;&#x65B0;&#x540E;&#x7684;&#x5BF9;&#x8C61;&#x6216;&#x6307;&#x5B9A;&#x4E00;&#x4E9B;&#x66F4;&#x65B0;&#x7684;&#x64CD;&#x4F5C;&#x7B26;<ul>
<li>$set&#x76F4;&#x63A5;&#x6307;&#x5B9A;&#x66F4;&#x65B0;&#x540E;&#x7684;&#x503C;</li>
<li>$inc&#x5728;&#x539F;&#x57FA;&#x7840;&#x4E0A;&#x7D2F;&#x52A0;</li>
</ul>
</li>
<li>upsert  &#x53EF;&#x9009;&#xFF0C;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x610F;&#x601D;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x7B26;&#x5408;&#x6761;&#x4EF6;&#x7684;&#x8BB0;&#x5F55;&#x65F6;&#x662F;&#x5426;&#x63D2;&#x5165;updateObj.  &#x9ED8;&#x8BA4;&#x662F;false,&#x4E0D;&#x63D2;&#x5165;&#x3002;</li>
<li>multi  &#x53EF;&#x9009;&#xFF0C;mongodb &#x9ED8;&#x8BA4;&#x53EA;&#x66F4;&#x65B0;&#x627E;&#x5230;&#x7684;&#x7B2C;&#x4E00;&#x6761;&#x8BB0;&#x5F55;&#xFF0C;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;true,&#x5C31;&#x66F4;&#x65B0;&#x6240;&#x6709;&#x7B26;&#x5408;&#x6761;&#x4EF6;&#x7684;&#x8BB0;&#x5F55;&#x3002;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x5C06;<code>students</code>&#x96C6;&#x5408;&#x4E2D;&#x6570;&#x636E;&#x4E2D;<code>name</code>&#x662F;zfpx2&#x7684;&#x503C;&#x4FEE;&#x6539;&#x4E3A;zfpx22</p>
<pre><code>&gt; db.students.update({name:&apos;zfpx2&apos;},{age:300});
WriteResult({ &quot;nMatched&quot; : 1, &quot;nUpserted&quot; : 0, &quot;nModified&quot; : 1 })
</code></pre><blockquote>
<p>&#x6CE8;&#xFF1A;&#x5982;&#x679C;&#x6709;&#x591A;&#x6761;name&#x662F;zfpx2&#x7684;&#x6570;&#x636E;&#x53EA;&#x66F4;&#x65B0;&#x4E00;&#x6761;,&#x5982;&#x679C;&#x60F3;&#x5168;&#x90E8;&#x66F4;&#x65B0;&#x9700;&#x8981;&#x6307;&#x5B9A;<code>{multi:true}</code>&#x7684;&#x53C2;&#x6570;</p>
<pre><code class="lang-js">db.students.update({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zfpx2&apos;</span>},{<span class="hljs-attr">$set</span>:{<span class="hljs-attr">age</span>:<span class="hljs-number">300</span>}},{<span class="hljs-attr">multi</span>:<span class="hljs-literal">true</span>});
WriteResult({ <span class="hljs-string">&quot;nMatched&quot;</span> : <span class="hljs-number">2</span>, <span class="hljs-string">&quot;nUpserted&quot;</span> : <span class="hljs-number">0</span>, <span class="hljs-string">&quot;nModified&quot;</span> : <span class="hljs-number">1</span> })
</code></pre>
</blockquote>
<h3 id="t249.1 $set">9.1 $set <a href="#t249.1 $set"> # </a></h3>
<p>&#x76F4;&#x63A5;&#x6307;&#x5B9A;&#x66F4;&#x65B0;&#x540E;&#x7684;&#x503C;</p>
<h3 id="t259.2 $inc">9.2 $inc <a href="#t259.2 $inc"> # </a></h3>
<p>&#x5728;&#x539F;&#x57FA;&#x7840;&#x4E0A;&#x7D2F;&#x52A0;</p>
<h3 id="t269.3 $unset">9.3 $unset <a href="#t269.3 $unset"> # </a></h3>
<p>&#x5220;&#x9664;&#x6307;&#x5B9A;&#x7684;&#x952E;</p>
<h3 id="t279.4 upsert">9.4 upsert <a href="#t279.4 upsert"> # </a></h3>
<p>&#x63D2;&#x5165;&#x6216;&#x66F4;&#x65B0;</p>
<h3 id="t289.5 multi">9.5 multi <a href="#t289.5 multi"> # </a></h3>
<p>&#x6279;&#x91CF;&#x63D2;&#x5165;</p>
<h3 id="t299.6 $push">9.6 $push <a href="#t299.6 $push"> # </a></h3>
<p>&#x5411;&#x6570;&#x7EC4;&#x4E2D;&#x6DFB;&#x52A0;&#x5143;&#x7D20; </p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> result = db.student.update({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>},{
    <span class="hljs-attr">$push</span>:{<span class="hljs-string">&quot;hobbys&quot;</span>:<span class="hljs-string">&quot;smoking&quot;</span>}
});
</code></pre>
<h3 id="t309.7 $ne">9.7 $ne <a href="#t309.7 $ne"> # </a></h3>
<pre><code class="lang-js">db.student.update({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>,<span class="hljs-attr">friends</span>:{<span class="hljs-attr">$ne</span>:<span class="hljs-string">&apos;Nami&apos;</span>}},{
    <span class="hljs-attr">$push</span>:{<span class="hljs-string">&quot;friends&quot;</span>:<span class="hljs-string">&quot;Nami&quot;</span>}
});
</code></pre>
<h3 id="t319.8 $addToSet">9.8 $addToSet <a href="#t319.8 $addToSet"> # </a></h3>
<pre><code class="lang-js">db.student.update({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>},{<span class="hljs-attr">$addToSet</span>:{<span class="hljs-attr">friends</span>:<span class="hljs-string">&quot;Wusopu&quot;</span>}});
</code></pre>
<h3 id="t329.9 $each">9.9 $each <a href="#t329.9 $each"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> newFriends = [<span class="hljs-string">&quot;A&quot;</span>,<span class="hljs-string">&apos;B&apos;</span>];
<span class="hljs-keyword">var</span> result = db.student.update({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>},{<span class="hljs-attr">$addToSet</span>:{<span class="hljs-attr">friends</span>:{<span class="hljs-attr">$each</span>:newFriends}}});
</code></pre>
<h3 id="t339.10  $pop">9.10  $pop <a href="#t339.10  $pop"> # </a></h3>
<pre><code class="lang-js">db.student.update({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>},{<span class="hljs-attr">$pop</span>:{
    <span class="hljs-attr">friends</span>:<span class="hljs-number">1</span>
}});
</code></pre>
<h3 id="t349.11 &#x4FEE;&#x6539;&#x6307;&#x5B9A;&#x7D22;&#x5F15;&#x5143;&#x7D20;">9.11 &#x4FEE;&#x6539;&#x6307;&#x5B9A;&#x7D22;&#x5F15;&#x5143;&#x7D20; <a href="#t349.11 &#x4FEE;&#x6539;&#x6307;&#x5B9A;&#x7D22;&#x5F15;&#x5143;&#x7D20;"> # </a></h3>
<pre><code class="lang-js"> db.student.update({<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>},{<span class="hljs-attr">$set</span>:{
    <span class="hljs-string">&quot;friends.1&quot;</span>:<span class="hljs-string">&quot;Nami2&quot;</span>
}});
</code></pre>
<h3 id="t359.12  runCommand">9.12  runCommand <a href="#t359.12  runCommand"> # </a></h3>
<pre><code class="lang-js"> <span class="hljs-keyword">var</span> modify = {
    <span class="hljs-attr">findAndModify</span>:<span class="hljs-string">&apos;student&apos;</span>,
    <span class="hljs-attr">query</span>:{<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;&#x5F20;&#x4E09;&apos;</span>},
    <span class="hljs-attr">update</span>:{<span class="hljs-attr">$set</span>:{<span class="hljs-attr">age</span>:<span class="hljs-number">100</span>}},
    <span class="hljs-attr">fields</span>:{<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;1&apos;</span>},
    <span class="hljs-attr">sort</span>:<span class="hljs-literal">true</span>,
    <span class="hljs-attr">new</span>:<span class="hljs-literal">true</span> <span class="hljs-comment">//&#x8FD4;&#x56DE;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x503C;</span>
}

<span class="hljs-keyword">var</span> result = db.runCommand(modify);
printjson(result);
</code></pre>
<h2 id="t3610. &#x6587;&#x6863;&#x7684;&#x5220;&#x9664;">10. &#x6587;&#x6863;&#x7684;&#x5220;&#x9664; <a href="#t3610. &#x6587;&#x6863;&#x7684;&#x5220;&#x9664;"> # </a></h2>
<p>remove&#x65B9;&#x6CD5;&#x662F;&#x7528;&#x6765;&#x79FB;&#x9664;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x6570;&#x636E;</p>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collection.remove(
   &lt;query&gt;,
   {
     justOne: &lt;boolean&gt;
   }
)
</code></pre><p><strong>&#x53C2;&#x6570;&#x8BF4;&#x660E;</strong></p>
<ul>
<li>query :&#xFF08;&#x53EF;&#x9009;&#xFF09;&#x5220;&#x9664;&#x7684;&#x6587;&#x6863;&#x7684;&#x6761;&#x4EF6;&#x3002;</li>
<li>justOne : &#xFF08;&#x53EF;&#x9009;&#xFF09;&#x5982;&#x679C;&#x8BBE;&#x4E3A; true &#x6216; 1&#xFF0C;&#x5219;&#x53EA;&#x5220;&#x9664;&#x5339;&#x914D;&#x5230;&#x7684;&#x591A;&#x4E2A;&#x6587;&#x6863;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x5220;&#x9664;worker&#x96C6;&#x5408;&#x91CC;name&#x662F;zfpx2&#x7684;&#x6240;&#x6709;&#x6587;&#x6863;&#x6570;&#x636E;</p>
<pre><code>&gt; db.students.remove({name:&apos;zfpx2&apos;});
WriteResult({ &quot;nRemoved&quot; : 2 })
</code></pre><p>&#x5373;&#x4F7F;&#x5339;&#x914D;&#x591A;&#x6761;&#x4E5F;&#x53EA;&#x5220;&#x9664;&#x4E00;&#x6761;</p>
<pre><code>&gt; db.students.remove({name:&quot;zfpx2&quot;},{justOne:true})
WriteResult({ &quot;nRemoved&quot; : 1 })
</code></pre><h2 id="t3711. &#x67E5;&#x8BE2;&#x6587;&#x6863;">11. &#x67E5;&#x8BE2;&#x6587;&#x6863; <a href="#t3711. &#x67E5;&#x8BE2;&#x6587;&#x6863;"> # </a></h2>
<h3 id="t3811.1 find">11.1 find <a href="#t3811.1 find"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collection_name.find()
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collection_name &#x96C6;&#x5408;&#x7684;&#x540D;&#x5B57;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;students&#x4E0B;&#x6240;&#x6709;&#x7684;&#x6587;&#x6863;</p>
<pre><code>db.students.find()
</code></pre><h3 id="t3911.2 &#x67E5;&#x8BE2;&#x6307;&#x5B9A;&#x5217;">11.2 &#x67E5;&#x8BE2;&#x6307;&#x5B9A;&#x5217; <a href="#t3911.2 &#x67E5;&#x8BE2;&#x6307;&#x5B9A;&#x5217;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collection_name.find({queryWhere},{key:1,key:1})
</code></pre><p><strong>&#x53C2;&#x6570;&#x5217;&#x8868;</strong></p>
<ul>
<li>collection_name  &#x96C6;&#x5408;&#x7684;&#x540D;&#x5B57;</li>
<li>queryWhere &#x53C2;&#x9605;&#x67E5;&#x8BE2;&#x6761;&#x4EF6;&#x64CD;&#x4F5C;&#x7B26;</li>
<li>key &#x6307;&#x5B9A;&#x8981;&#x8FD4;&#x56DE;&#x7684;&#x5217;</li>
<li>1 &#x8868;&#x793A;&#x8981;&#x663E;&#x793A;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x53EA;&#x8FD4;&#x56DE;&#x663E;&#x793A;age&#x5217;</p>
<pre><code>&gt; db.students.find({},{age:1});
</code></pre><h3 id="t4011.3 findOne">11.3 findOne <a href="#t4011.3 findOne"> # </a></h3>
<p>&#x67E5;&#x8BE2;&#x5339;&#x914D;&#x7ED3;&#x679C;&#x7684;&#x7B2C;&#x4E00;&#x6761;&#x6570;&#x636E;
<strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collection_name.findOne()
</code></pre><p><strong>&#x5B9E;&#x4F8B;</strong></p>
<pre><code>db.students.findOne()
</code></pre><h3 id="t4111.4 $in">11.4 $in <a href="#t4111.4 $in"> # </a></h3>
<pre><code class="lang-js">db.student.find({<span class="hljs-attr">age</span>:{<span class="hljs-attr">$in</span>:[<span class="hljs-number">30</span>,<span class="hljs-number">100</span>]}},{<span class="hljs-attr">name</span>:<span class="hljs-number">1</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">1</span>});
</code></pre>
<h3 id="t4211.5 $nin">11.5 $nin <a href="#t4211.5 $nin"> # </a></h3>
<pre><code class="lang-js">db.student.find({<span class="hljs-attr">age</span>:{<span class="hljs-attr">$nin</span>:[<span class="hljs-number">30</span>,<span class="hljs-number">100</span>]}},{<span class="hljs-attr">name</span>:<span class="hljs-number">1</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">1</span>});
</code></pre>
<h3 id="t4311.6 $nin">11.6 $nin <a href="#t4311.6 $nin"> # </a></h3>
<pre><code class="lang-js">db.student.find({<span class="hljs-attr">age</span>:{<span class="hljs-attr">$in</span>:[<span class="hljs-number">30</span>,<span class="hljs-number">100</span>]}},{<span class="hljs-attr">name</span>:<span class="hljs-number">1</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">1</span>});
</code></pre>
<h3 id="t4411.7  $not">11.7  $not <a href="#t4411.7  $not"> # </a></h3>
<pre><code class="lang-js">db.student.find({<span class="hljs-attr">age</span>:{<span class="hljs-attr">$not</span>:{<span class="hljs-attr">$gte</span>:<span class="hljs-number">20</span>,<span class="hljs-attr">$lte</span>:<span class="hljs-number">30</span>}}});
</code></pre>
<h3 id="t4511.8  array">11.8  array <a href="#t4511.8  array"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-comment">//&#x6309;&#x6240;&#x6709;&#x5143;&#x7D20;&#x5339;&#x914D;</span>
<span class="hljs-comment">//let result = db.student.find({friends:[ &quot;Lufy&quot;, &quot;Nami2&quot;, &quot;Wusopu&quot;, &quot;A&quot; ]});</span>
<span class="hljs-comment">//&#x5339;&#x914D;&#x4E00;&#x6761;</span>
<span class="hljs-comment">//let result = db.student.find({friends:&quot;A&quot;});</span>
<span class="hljs-comment">//$all</span>
<span class="hljs-comment">//let result = db.student.find({friends:{$all:[&apos;A&apos;,&quot;Lufy&quot;]}});</span>
<span class="hljs-comment">//$in</span>
<span class="hljs-comment">//let result = db.student.find({friends:{$in:[&apos;A&apos;,&quot;Lufy&quot;]}});</span>
<span class="hljs-comment">//$size</span>
<span class="hljs-comment">//let result = db.student.find({friends:{$size:4}});</span>
<span class="hljs-comment">//$slice</span>
<span class="hljs-comment">//let result = db.student.find({friends:{$size:5}},{name:1,friends:{$slice:1}});</span>
<span class="hljs-comment">//let result = db.student.find({friends:{$size:5}},{name:1,friends:{$slice:-1}});</span>
</code></pre>
<h3 id="t4611.9   where">11.9   where <a href="#t4611.9   where"> # </a></h3>
<pre><code class="lang-js">db.student.find({<span class="hljs-attr">$where</span>:<span class="hljs-string">&quot;this.age&gt;30&quot;</span>},{<span class="hljs-attr">name</span>:<span class="hljs-number">1</span>,<span class="hljs-attr">age</span>:<span class="hljs-number">1</span>});
</code></pre>
<h3 id="t4711.10   cursor">11.10   cursor <a href="#t4711.10   cursor"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> result = db.student.find();

<span class="hljs-comment">//while(result.hasNext()){</span>
<span class="hljs-comment">//    printjson(result.next());</span>
<span class="hljs-comment">//}</span>

result.forEach(<span class="hljs-function"><span class="hljs-params">element</span>=&gt;</span>printjson(element));
</code></pre>
<h2 id="t4812. &#x6761;&#x4EF6;&#x64CD;&#x4F5C;&#x7B26;">12. &#x6761;&#x4EF6;&#x64CD;&#x4F5C;&#x7B26; <a href="#t4812. &#x6761;&#x4EF6;&#x64CD;&#x4F5C;&#x7B26;"> # </a></h2>
<p>&#x6761;&#x4EF6;&#x64CD;&#x4F5C;&#x7B26;&#x7528;&#x4E8E;&#x6BD4;&#x8F83;&#x4E24;&#x4E2A;&#x8868;&#x8FBE;&#x5F0F;&#x5E76;&#x4ECE;mongoDB&#x96C6;&#x5408;&#x4E2D;&#x83B7;&#x53D6;&#x6570;&#x636E;</p>
<h3 id="t4912.1 &#x5927;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26;">12.1 &#x5927;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26; <a href="#t4912.1 &#x5927;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find({&lt;key&gt;:{$gt:&lt;value&gt;}})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name  &#x96C6;&#x5408;&#x540D;&#x79F0;</li>
<li>key   &#x5B57;&#x6BB5;</li>
<li>value   &#x503C;</li>
</ul>
<p>&#x67E5;&#x8BE2;age &#x5927;&#x4E8E; 30&#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({age:{$gt:30}})
</code></pre><h3 id="t5012.2 &#x5927;&#x4E8E;&#x7B49;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26;">12.2 &#x5927;&#x4E8E;&#x7B49;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26; <a href="#t5012.2 &#x5927;&#x4E8E;&#x7B49;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find({&lt;key&gt;:{$gte:&lt;value&gt;}})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name &#x96C6;&#x5408;&#x540D;&#x79F0;</li>
<li>key  &#x5B57;&#x6BB5;</li>
<li>value  &#x503C;</li>
</ul>
<p>&#x67E5;&#x8BE2;age 3&#x5927;&#x4E8E;&#x7B49;&#x4E8E;30 &#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({age: {$gte: 30}})
</code></pre><h3 id="t5112.3 &#x5C0F;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26;">12.3 &#x5C0F;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26; <a href="#t5112.3 &#x5C0F;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find( {&lt;key&gt;:{$lt:&lt;value&gt;}})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name&#x96C6;&#x5408;&#x540D;&#x79F0;</li>
<li>key &#x5B57;&#x6BB5;</li>
<li>value &#x503C;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong></p>
<pre><code>db.students.find({age: {$lt: 30}}) &#x67E5;&#x8BE2;age &#x5C0F;&#x4E8E;30&#x7684;&#x6570;&#x636E;
</code></pre><p><img src="http://7xjf2l.com2.z0.glb.qiniucdn.com/3.mongodb-16-3.png" class="img-responsive"></p>
<h3 id="t5212.4 &#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26;">12.4 &#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26; <a href="#t5212.4 &#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;&#x64CD;&#x4F5C;&#x7B26;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find({&lt;key&gt;:{$lte:&lt;value&gt;}})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name&#x96C6;&#x5408;&#x540D;&#x8BCD;</li>
<li>key&#x5B57;&#x6BB5;</li>
<li>value&#x503C;</li>
</ul>
<p>&#x67E5;&#x8BE2;age &#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;30&#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({age: {$lte: 30}})
</code></pre><h3 id="t5312.5 &#x540C;&#x65F6;&#x4F7F;&#x7528; $gte&#x548C;$lte">12.5 &#x540C;&#x65F6;&#x4F7F;&#x7528; $gte&#x548C;$lte <a href="#t5312.5 &#x540C;&#x65F6;&#x4F7F;&#x7528; $gte&#x548C;$lte"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find({&lt;key&gt;:{$gte:&lt;value&gt;},&lt;key&gt;:{$lte:&lt;value&gt;}})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name &#x96C6;&#x5408;&#x540D;&#x79F0;</li>
<li>key &#x5B57;&#x6BB5;</li>
<li>value &#x503C;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;age &#x5927;&#x4E8E;&#x7B49;&#x4E8E; 30 &#x5E76;&#x4E14; age &#x5C0F;&#x4E8E;&#x7B49;&#x4E8E; 50  &#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({age: {$gte: 30, $lte: 50}})
</code></pre><h3 id="t5412.6 &#x7B49;&#x4E8E;">12.6 &#x7B49;&#x4E8E; <a href="#t5412.6 &#x7B49;&#x4E8E;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find({&lt;key&gt;:&lt;value&gt;,&lt;key&gt;:&lt;value&gt;})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name&#x96C6;&#x5408;&#x540D;&#x8BCD;</li>
<li>key&#x5B57;&#x6BB5;</li>
<li>value&#x503C;</li>
</ul>
<p>&#x67E5;&#x8BE2;age = 30&#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({&quot;age&quot;: 30})`
</code></pre><h3 id="t5512.7 &#x4F7F;&#x7528; _id&#x8FDB;&#x884C;&#x67E5;&#x8BE2;">12.7 &#x4F7F;&#x7528; _id&#x8FDB;&#x884C;&#x67E5;&#x8BE2; <a href="#t5512.7 &#x4F7F;&#x7528; _id&#x8FDB;&#x884C;&#x67E5;&#x8BE2;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find({&quot;_id&quot; : ObjectId(&quot;value&quot;)})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>value  <code>_id</code>&#x7684;&#x503C;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;_id&#x662F; 562af23062d5a57609133974 &#x6570;&#x636E;</p>
<pre><code>&gt; db.students.find({_id:ObjectId(&quot;5adb666ecd738e9771638985&quot;)});
{ &quot;_id&quot; : ObjectId(&quot;5adb666ecd738e9771638985&quot;), &quot;name&quot; : &quot;zzzz&quot; }
</code></pre><h3 id="t5612.8 &#x67E5;&#x8BE2;&#x7ED3;&#x679C;&#x96C6;&#x7684;&#x6761;&#x6570;">12.8 &#x67E5;&#x8BE2;&#x7ED3;&#x679C;&#x96C6;&#x7684;&#x6761;&#x6570; <a href="#t5612.8 &#x67E5;&#x8BE2;&#x7ED3;&#x679C;&#x96C6;&#x7684;&#x6761;&#x6570;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find().count()
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name &#x96C6;&#x5408;&#x540D;&#x79F0;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong></p>
<pre><code>db.students.find().count()
</code></pre><h3 id="t5712.9 &#x6B63;&#x5219;&#x5339;&#x914D;">12.9 &#x6B63;&#x5219;&#x5339;&#x914D; <a href="#t5712.9 &#x6B63;&#x5219;&#x5339;&#x914D;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collection.find({key:/value/})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name &#x96C6;&#x5408;&#x540D;&#x79F0;</li>
<li>key &#x5B57;&#x6BB5;</li>
<li>value &#x503C;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;name&#x91CC;&#x5305;&#x542B;zhang&#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({name:/value/})
</code></pre><p>&#x67E5;&#x8BE2;&#x67D0;&#x4E2A;&#x5B57;&#x6BB5;&#x7684;&#x503C;&#x5F53;&#x4E2D;&#x662F;&#x5426;&#x4EE5;&#x53E6;&#x4E00;&#x4E2A;&#x503C;&#x5F00;&#x5934;</p>
<pre><code>db.students.find({name:/^zhang/})
</code></pre><h2 id="t5813. &#x4E0E;&#x548C;&#x6216;">13. &#x4E0E;&#x548C;&#x6216; <a href="#t5813. &#x4E0E;&#x548C;&#x6216;"> # </a></h2>
<h3 id="t5913.1 and">13.1 and <a href="#t5913.1 and"> # </a></h3>
<p>find&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x4F20;&#x5165;&#x591A;&#x4E2A;&#x952E;(key)&#xFF0C;&#x6BCF;&#x4E2A;&#x952E;(key)&#x4EE5;&#x9017;&#x53F7;&#x9694;&#x5F00;</p>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collection_name.find({key1:value1, key2:value2})
</code></pre><p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;name&#x662F;zfpx&#x5E76;&#x4E14;age&#x662F;1&#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({name:&apos;zfpx&apos;,age:1})
</code></pre><h3 id="t6013.2 or">13.2 or <a href="#t6013.2 or"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collection_name.find(
   {
      $or: [
   {key1: value1}, {key2:value2}
      ]
   }
)
</code></pre><p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;age = 30 &#x6216;&#x8005; age = 50  &#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({$or:[{age:30},{age:50}]})
</code></pre><h3 id="t6113.3 and&#x548C;or&#x8054;&#x7528;">13.3 and&#x548C;or&#x8054;&#x7528; <a href="#t6113.3 and&#x548C;or&#x8054;&#x7528;"> # </a></h3>
<p><strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collection_name.find(
   {
     key1:value1,
     key2:value2,
     $or: [
   {key1: value1},
   {key2:value2}
     ]
   }
)
</code></pre><p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2; name&#x662F;zfpx &#x5E76;&#x4E14; age&#x662F;30 &#x6216;&#x8005; age&#x662F; 50 &#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find({name:&apos;zfpx&apos;,$or:[{age:30},{age:50}]})
</code></pre><h2 id="t6214. &#x5206;&#x9875;&#x67E5;&#x8BE2;">14. &#x5206;&#x9875;&#x67E5;&#x8BE2; <a href="#t6214. &#x5206;&#x9875;&#x67E5;&#x8BE2;"> # </a></h2>
<h3 id="t6314.1 limit">14.1 limit <a href="#t6314.1 limit"> # </a></h3>
<p>&#x8BFB;&#x53D6;&#x6307;&#x5B9A;&#x6570;&#x91CF;&#x7684;&#x6570;&#x636E;&#x8BB0;&#x5F55;
<strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find().limit(number)
</code></pre><p><strong> &#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name&#x96C6;&#x5408;</li>
<li>number&#x8BFB;&#x53D6;&#x7684;&#x6761;&#x6570;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;&#x524D;3&#x6761;&#x6570;&#x636E;</p>
<pre><code>db.students.find().limit(3)
</code></pre><h3 id="t6414.2 skip">14.2 skip <a href="#t6414.2 skip"> # </a></h3>
<p>&#x8DF3;&#x8FC7;&#x6307;&#x5B9A;&#x6570;&#x91CF;&#x7684;&#x6570;&#x636E;&#xFF0C;skip&#x65B9;&#x6CD5;&#x540C;&#x6837;&#x63A5;&#x53D7;&#x4E00;&#x4E2A;&#x6570;&#x5B57;&#x53C2;&#x6570;&#x4F5C;&#x4E3A;&#x8DF3;&#x8FC7;&#x7684;&#x8BB0;&#x5F55;&#x6761;&#x6570;
<strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find().skip(number)
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name&#x96C6;&#x5408;</li>
<li>number&#x8DF3;&#x8FC7;&#x7684;&#x6761;&#x6570;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;3&#x6761;&#x4EE5;&#x540E;&#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find().skip(3)
</code></pre><h3 id="t6514.3 skip+limit">14.3 skip+limit <a href="#t6514.3 skip+limit"> # </a></h3>
<p>&#x901A;&#x5E38;&#x7528;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x6765;&#x5B9E;&#x73B0;&#x5206;&#x9875;&#x529F;&#x80FD;
<strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find().skip(skipNum).limit(limitNum)
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name &#x96C6;&#x5408;&#x540D;&#x79F0;</li>
<li>skipNum &#x8DF3;&#x8FC7;&#x7684;&#x6761;&#x6570;</li>
<li>limitNum &#x9650;&#x5236;&#x8FD4;&#x56DE;&#x7684;&#x6761;&#x6570;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;&#x5728;4-6&#x4E4B;&#x95F4;&#x7684;&#x6570;&#x636E;</p>
<pre><code>db.students.find().skip(3).limit(3);
</code></pre><h3 id="t6614.4 sort&#x6392;&#x5E8F;">14.4 sort&#x6392;&#x5E8F; <a href="#t6614.4 sort&#x6392;&#x5E8F;"> # </a></h3>
<p>sort()&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x6392;&#x5E8F;&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x5E76;&#x4F7F;&#x7528; 1 &#x548C; -1 &#x6765;&#x6307;&#x5B9A;&#x6392;&#x5E8F;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x5176;&#x4E2D; 1 &#x4E3A;&#x5347;&#x5E8F;&#x6392;&#x5217;&#xFF0C;&#x800C;-1&#x662F;&#x7528;&#x4E8E;&#x964D;&#x5E8F;&#x6392;&#x5217;&#x3002;
<strong>&#x8BED;&#x6CD5;</strong></p>
<pre><code>db.collectoin_name.find().sort({key:1})
db.collectoin_name.find().sort({key:-1})
</code></pre><p><strong>&#x53C2;&#x6570;</strong></p>
<ul>
<li>collectoin_name&#x96C6;&#x5408;</li>
<li>key&#x8868;&#x793A;&#x5B57;&#x6BB5;</li>
</ul>
<p><strong>&#x5B9E;&#x4F8B;</strong>
&#x67E5;&#x8BE2;&#x51FA;&#x5E76;&#x5347;&#x5E8F;&#x6392;&#x5E8F; {age:1}  age&#x8868;&#x793A;&#x6309;&#x90A3;&#x4E2A;&#x5B57;&#x6BB5;&#x6392;&#x5E8F; 1&#x8868;&#x793A;&#x5347;&#x5E8F;</p>
<pre><code>db.students.find().sort({age:1})
</code></pre><h3 id="t6715. &#x6267;&#x884C;&#x811A;&#x672C;">15. &#x6267;&#x884C;&#x811A;&#x672C; <a href="#t6715. &#x6267;&#x884C;&#x811A;&#x672C;"> # </a></h3>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> username = <span class="hljs-string">&apos;zfpx&apos;</span>;
<span class="hljs-keyword">var</span> password = <span class="hljs-string">&apos;123456&apos;</span>;
<span class="hljs-keyword">var</span> user = { <span class="hljs-string">&quot;username&quot;</span>: username, <span class="hljs-string">&quot;password&quot;</span>: password };
<span class="hljs-keyword">var</span> db = connect(<span class="hljs-string">&apos;students&apos;</span>);<span class="hljs-comment">//&#x9009;&#x62E9;users&#x6570;&#x636E;&#x5E93;</span>
<span class="hljs-keyword">var</span> result = db.users.insert(user);
print(<span class="hljs-string">&apos;write &apos;</span> + result);
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> start = <span class="hljs-built_in">Date</span>.now();
<span class="hljs-keyword">var</span> db = connect(<span class="hljs-string">&apos;students&apos;</span>);
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">1000</span>; i++) {
    db.users.insert({ <span class="hljs-string">&quot;username&quot;</span>: <span class="hljs-string">&quot;zfpx&quot;</span> + i });
}
<span class="hljs-keyword">var</span> cost = <span class="hljs-built_in">Date</span>.now() - start;
print(<span class="hljs-string">&apos;cost &apos;</span> + cost + <span class="hljs-string">&apos; ms&apos;</span>);
</code></pre>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> start = <span class="hljs-built_in">Date</span>.now();
<span class="hljs-keyword">var</span> db = connect(<span class="hljs-string">&apos;students&apos;</span>);
<span class="hljs-keyword">var</span> users = [];
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">1000</span>; i++) {
    users.push({ <span class="hljs-string">&quot;username&quot;</span>: <span class="hljs-string">&quot;zfpx&quot;</span> + i });
}
db.users.insert(users);
<span class="hljs-keyword">var</span> cost = <span class="hljs-built_in">Date</span>.now() - start;
print(<span class="hljs-string">&apos;cost &apos;</span> + cost + <span class="hljs-string">&apos; ms&apos;</span>);
</code></pre>
<h3 id="t6816 &#x7D22;&#x5F15;">16 &#x7D22;&#x5F15; <a href="#t6816 &#x7D22;&#x5F15;"> # </a></h3>
<pre><code class="lang-js">db.users.getIndexes();
db.users.ensureIndex({<span class="hljs-attr">name</span>:<span class="hljs-number">1</span>});
db.users.find({<span class="hljs-attr">someother</span>:<span class="hljs-string">&apos;28903&apos;</span>,<span class="hljs-attr">name</span>:<span class="hljs-string">&apos;huqo3vx&apos;</span>}).hint({<span class="hljs-attr">someother</span>:<span class="hljs-number">1</span>});

db.articles.ensureIndex({<span class="hljs-attr">content</span>:<span class="hljs-string">&apos;text&apos;</span>});
db.articles.find({<span class="hljs-attr">$text</span>:{<span class="hljs-attr">$search</span>:<span class="hljs-string">&quot;1&quot;</span>}});
db.articles.find({<span class="hljs-attr">$text</span>:{<span class="hljs-attr">$search</span>:<span class="hljs-string">&quot;1 2 3 -4&quot;</span>}});
db.articles.find({<span class="hljs-attr">$text</span>:{<span class="hljs-attr">$search</span>:<span class="hljs-string">&quot;1 2 3 -4&quot;</span>}});
db.articles.find({<span class="hljs-attr">$text</span>:{<span class="hljs-attr">$search</span>:<span class="hljs-string">&quot;\&quot;2 3\&quot;&quot;</span>}});
</code></pre>
<h3 id="t69&#x5907;&#x4EFD;&#x4E0E;&#x5BFC;&#x51FA;">&#x5907;&#x4EFD;&#x4E0E;&#x5BFC;&#x51FA; <a href="#t69&#x5907;&#x4EFD;&#x4E0E;&#x5BFC;&#x51FA;"> # </a></h3>
<pre><code class="lang-js">mongodump
    -- host <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span>
    -- port <span class="hljs-number">27017</span>
    -- out D:<span class="hljs-regexp">/databack/</span>backup
    -- collection mycollection
    -- db test
    -- username
    -- password
<span class="hljs-comment">//mongodump --host 127.0.0.1 --port 27017 --out ./backup --collection users --db school</span>
<span class="hljs-comment">//db.users.drop();</span>

mongorestore
--host
--port
--username
--password

mongorestore --host <span class="hljs-number">127.0</span><span class="hljs-number">.0</span><span class="hljs-number">.1</span> --port <span class="hljs-number">27017</span> D:<span class="hljs-comment">//backup/</span>
</code></pre>
<h3 id="t70&#x6743;&#x9650;">&#x6743;&#x9650; <a href="#t70&#x6743;&#x9650;"> # </a></h3>
<pre><code class="lang-js">db.createUser({
    <span class="hljs-attr">user</span>:<span class="hljs-string">&apos;zfpx&apos;</span>,
    <span class="hljs-attr">pwd</span>:<span class="hljs-string">&apos;123456&apos;</span>,
    <span class="hljs-attr">customData</span>:{
        <span class="hljs-attr">name</span>:<span class="hljs-string">&apos;zhufengpeixun&apos;</span>,
        <span class="hljs-attr">email</span>:<span class="hljs-string">&apos;zhufengpeixun@126.com&apos;</span>,
        <span class="hljs-attr">age</span>:<span class="hljs-number">18</span>
    },
    <span class="hljs-attr">roles</span>:[
        {
          <span class="hljs-attr">role</span>:<span class="hljs-string">&apos;readWrite&apos;</span>,
          <span class="hljs-attr">db</span>:<span class="hljs-string">&apos;school&apos;</span>
        },
        <span class="hljs-string">&apos;read&apos;</span>
    ]
});
<span class="hljs-comment">// db.system.users.remove({user:&apos;zfpx&apos;});</span>
<span class="hljs-comment">// mongod --auth</span>
<span class="hljs-comment">// mongo -u zfpx -p 123456 127.0.0.1:27017/admin</span>
</code></pre>
<h2 id="t71&#x9644;&#x5F55;">&#x9644;&#x5F55; <a href="#t71&#x9644;&#x5F55;"> # </a></h2>
<h3 id="t72ObjectId&#x6784;&#x6210;">ObjectId&#x6784;&#x6210; <a href="#t72ObjectId&#x6784;&#x6210;"> # </a></h3>
<p>&#x4E4B;&#x524D;&#x6211;&#x4EEC;&#x4F7F;&#x7528;MySQL&#x7B49;&#x5173;&#x7CFB;&#x578B;&#x6570;&#x636E;&#x5E93;&#x65F6;&#xFF0C;&#x4E3B;&#x952E;&#x90FD;&#x662F;&#x8BBE;&#x7F6E;&#x6210;&#x81EA;&#x589E;&#x7684;&#x3002;&#x4F46;&#x5728;&#x5206;&#x5E03;&#x5F0F;&#x73AF;&#x5883;&#x4E0B;&#xFF0C;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x5C31;&#x4E0D;&#x53EF;&#x884C;&#x4E86;&#xFF0C;&#x4F1A;&#x4EA7;&#x751F;&#x51B2;&#x7A81;&#x3002;&#x4E3A;&#x6B64;&#xFF0C;MongoDB&#x91C7;&#x7528;&#x4E86;&#x4E00;&#x4E2A;&#x79F0;&#x4E4B;&#x4E3A;ObjectId&#x7684;&#x7C7B;&#x578B;&#x6765;&#x505A;&#x4E3B;&#x952E;&#x3002;ObjectId&#x662F;&#x4E00;&#x4E2A;12&#x5B57;&#x8282;&#x7684; BSON &#x7C7B;&#x578B;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x6309;&#x7167;&#x5B57;&#x8282;&#x987A;&#x5E8F;&#xFF0C;&#x4E00;&#x6B21;&#x4EE3;&#x8868;&#xFF1A;</p>
<ul>
<li>4&#x5B57;&#x8282;&#xFF1A;UNIX&#x65F6;&#x95F4;&#x6233;</li>
<li>3&#x5B57;&#x8282;&#xFF1A;&#x8868;&#x793A;&#x8FD0;&#x884C;MongoDB&#x7684;&#x673A;&#x5668;</li>
<li>2&#x5B57;&#x8282;&#xFF1A;&#x8868;&#x793A;&#x751F;&#x6210;&#x6B64;_id&#x7684;&#x8FDB;&#x7A0B;</li>
<li>3&#x5B57;&#x8282;&#xFF1A;&#x7531;&#x4E00;&#x4E2A;&#x968F;&#x673A;&#x6570;&#x5F00;&#x59CB;&#x7684;&#x8BA1;&#x6570;&#x5668;&#x751F;&#x6210;&#x7684;&#x503C;</li>
</ul>
<h2 id="t73&#x9644;&#x5F55;">&#x9644;&#x5F55; <a href="#t73&#x9644;&#x5F55;"> # </a></h2>
<h3 id="t74Mongodb&#x542F;&#x52A8;&#x547D;&#x4EE4;mongod&#x53C2;&#x6570;&#x8BF4;&#x660E;">Mongodb&#x542F;&#x52A8;&#x547D;&#x4EE4;mongod&#x53C2;&#x6570;&#x8BF4;&#x660E; <a href="#t74Mongodb&#x542F;&#x52A8;&#x547D;&#x4EE4;mongod&#x53C2;&#x6570;&#x8BF4;&#x660E;"> # </a></h3>
<table>
<thead>
<tr>
<th style="text-align:left">&#x9009;&#x9879;</th>
<th style="text-align:left">&#x542B;&#x4E49;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">--port</td>
<td style="text-align:left">&#x6307;&#x5B9A;&#x670D;&#x52A1;&#x7AEF;&#x53E3;&#x53F7;&#xFF0C;&#x9ED8;&#x8BA4;&#x7AEF;&#x53E3;27017</td>
</tr>
<tr>
<td style="text-align:left">--logpath</td>
<td style="text-align:left">&#x6307;&#x5B9A;MongoDB&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#xFF0C;&#x6CE8;&#x610F;&#x662F;&#x6307;&#x5B9A;&#x6587;&#x4EF6;&#x4E0D;&#x662F;&#x76EE;&#x5F55;</td>
</tr>
<tr>
<td style="text-align:left">--logappend</td>
<td style="text-align:left">&#x4F7F;&#x7528;&#x8FFD;&#x52A0;&#x7684;&#x65B9;&#x5F0F;&#x5199;&#x65E5;&#x5FD7;</td>
</tr>
<tr>
<td style="text-align:left">--dbpath</td>
<td style="text-align:left">&#x6307;&#x5B9A;&#x6570;&#x636E;&#x5E93;&#x8DEF;&#x5F84;</td>
</tr>
<tr>
<td style="text-align:left">--directoryperdb</td>
<td style="text-align:left">&#x8BBE;&#x7F6E;&#x6BCF;&#x4E2A;&#x6570;&#x636E;&#x5E93;&#x5C06;&#x88AB;&#x4FDD;&#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x76EE;&#x5F55;</td>
</tr>
</tbody>
</table>
<h2 id="t75&#x96C6;&#x5408;&#x547D;&#x4EE4;">&#x96C6;&#x5408;&#x547D;&#x4EE4; <a href="#t75&#x96C6;&#x5408;&#x547D;&#x4EE4;"> # </a></h2>
<ul>
<li>db.students.help();</li>
<li>DBCollection help</li>
<li>db.students.find().help() - show DBCursor help &#x663E;&#x793A;&#x6E38;&#x6807;&#x5E2E;&#x52A9;</li>
<li>db.students.count()   &#x663E;&#x793A;&#x6761;&#x6570;</li>
<li>db.students.copyTo(newColl) - duplicates collection by copying all docum
ents to newColl; no indexes are copied. &#x628A;&#x4E00;&#x4E2A;&#x65E7;&#x96C6;&#x5408;&#x62F7;&#x8D1D;&#x5230;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x96C6;&#x5408;&#xFF0C;&#x4E0D;&#x62F7;&#x8D1D;&#x7D22;&#x5F15;</li>
<li>db.students.convertToCapped(maxBytes) - calls {convertToCapped:&apos;students
&apos;, size:maxBytes}} command  </li>
<li>db.students.dataSize() &#x6570;&#x636E;&#x5927;&#x5C0F;</li>
<li>db.students.distinct( key ) - e.g. db.students.distinct( &apos;x&apos; ) &#x7EDF;&#x8BA1;&#x552F;&#x4E00;&#x7684;key&#x7684;&#x6570;&#x91CF;</li>
<li>db.students.drop() drop the collection &#xFF0C;&#x5220;&#x9664;&#x96C6;&#x5408;</li>
<li>db.students.dropIndex(index) - e.g. db.students.dropIndex( &quot;indexName&quot; ) &#x5220;&#x9664;&#x7D22;&#x5F15;
or db.students.dropIndex( { &quot;indexKey&quot; : 1 } )</li>
<li>db.students.dropIndexes() &#x5220;&#x9664; &#x6240;&#x6709;&#x7684;&#x7D22;&#x5F15;</li>
<li>db.students.ensureIndex(keypattern[,options]) - options is an object wit
h these possible fields: name, unique, dropDups &#x6DFB;&#x52A0;&#x7D22;&#x5F15;</li>
<li>db.students.reIndex() </li>
<li>db.students.find([query],[fields]) - query is an optional query filter.
fields is optional set of fields to return. &#x67E5;&#x627E;&#x6587;&#x6863;<pre><code>     e.g. db.students.find( {x:
</code></pre>77} , {name:1, x:1} )</li>
<li>db.students.find(...).count() &#x6570;&#x91CF;</li>
<li>db.students.find(...).limit(n) &#x9650;&#x5236;&#x8FD4;&#x56DE;&#x7684;&#x6761;&#x6570;</li>
<li>db.students.find(...).skip(n) &#x8BBE;&#x7F6E;&#x8DF3;&#x8FC7;&#x7684;&#x6761;&#x6570;</li>
<li>db.students.find(...).sort(...) &#x6392;&#x5E8F;</li>
<li>db.students.findOne([query]) &#x67E5;&#x627E;&#x4E00;&#x6761;</li>
<li>db.students.findAndModify( { update : ... , remove : bool [, query: {},
sort: {}, &apos;new&apos;: false] } )  &#x67E5;&#x627E;&#x5E76;&#x4E14;&#x4FEE;&#x6539; &#x66F4;&#x65B0;&#x540E;&#x7684;&#x503C;&#xFF0C;&#x662F;&#x5426;&#x5220;&#x9664;&#xFF0C;&#x67E5;&#x8BE2;&#x6761;&#x4EF6; &#x6392;&#x5E8F;  &#x662F;&#x5426;&#x8FD4;&#x56DE;&#x65B0;&#x503C;</li>
<li>db.students.getDB() get DB object associated with collection &#x83B7;&#x5F97;DB</li>
<li>db.students.getPlanCache() get query plan cache associated with collecti
on</li>
<li>db.students.getIndexes() &#x83B7;&#x53D6;&#x7D22;&#x5F15;</li>
<li>db.students.group( { key : ..., initial: ..., reduce : ...[, cond: ...]
} ) &#x5206;&#x7EC4;&#x7EDF;&#x8BA1; </li>
<li>db.students.insert(obj) &#x63D2;&#x5165;&#x6587;&#x6863;</li>
<li>db.students.mapReduce( mapFunction , reduceFunction , <optional params="">
) &#x7EDF;&#x8BA1; </optional></li>
<li>db.students.aggregate( [pipeline], <optional params=""> ) - performs an agg
regation on a collection; returns a cursor &#x805A;&#x5408;</optional></li>
<li>db.students.remove(query) &#x5220;&#x9664; </li>
<li>db.students.renameCollection( newName , <droptarget> ) renames the colle
ction. &#x91CD;&#x547D;&#x540D;&#x96C6;&#x5408;</droptarget></li>
<li>db.students.runCommand( name , <options> ) runs a db command with the gi
ven name where the first param is the collection name</options></li>
<li>db.students.save(obj) &#x4FDD;&#x5B58;&#x5BF9;&#x8C61;</li>
<li>db.students.stats() &#x7EDF;&#x8BA1;&#x4FE1;&#x606F;</li>
<li>db.students.storageSize() - includes free space allocated to this collec
tion</li>
<li>db.students.totalIndexSize() - size in bytes of all the indexes</li>
<li>db.students.totalSize() - storage allocated for all data and indexes</li>
<li>db.students.update(query, object[, upsert_bool, multi_bool]) - instead o
f two flags, you can pass an object with fields: upsert, multi &#x66F4;&#x65B0;</li>
<li>db.students.validate( <full> ) - SLOW</full></li>
<li>db.students.getShardVersion() - only for use with sharding</li>
<li>db.students.getShardDistribution() - prints statistics about data distri
bution in the cluster</li>
<li>db.students.getSplitKeysForChunks( <maxchunksize> ) - calculates split p
oints over all chunks and returns splitter function</maxchunksize></li>
<li>db.students.getWriteConcern() - returns the write concern used for any o
perations on this collection, inherited from server/db if set</li>
<li>db.students.setWriteConcern( <write concern="" doc=""> ) - sets the write conc
ern for writes to the collection</write></li>
<li>db.students.unsetWriteConcern( <write concern="" doc=""> ) - unsets the write
concern for writes to the collection</write></li>
</ul>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
